(function(global){
    function createXHR() {
        // 现在基本不需要写兼容代码
        var xhr = null;
        if (window.XMLHttpRequest) {
            // 火狐、Safari、IE7+ 、Chrome ....
            xhr = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            // IE6 或者 更低的版本
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            alert("您的浏览器不支持ajax");
        }
        return xhr;
    }
/*
option = {
    method: string,// 默认为 get
    url: string,
    async: boolean,// 默认为 true
    data: 请求参数(格式: key1=value1&key2=value2&...),
    success: function 回调函数
}
*/
    function ajax(option) {
        var async = false;
        if(option.async === undefined || option.async === true){
            // 未设置，默认为异步
            async = true;
        }
        var xhr = new createXHR();
        var method = "get";// 默认值
        if(option.method === "post"){
            method = "post";
        }
        xhr.onload = function(){
            option.success(xhr);
        }
        xhr.open(method, option.url, async);
        if(method === "post"){
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.send(option.data);
        } else {
            xhr.send();
        }
    }
    global.ajax = ajax;
})(window);